home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / m68k / fbug68k.arc / HANDLER.C < prev    next >
C/C++ Source or Header  |  1989-08-17  |  6KB  |  330 lines

  1. #include"userdef.h"
  2.  
  3. handler()
  4. {
  5. extern int stackptr;
  6. extern int regdata[];
  7. extern int tracecount;
  8. extern int oldbraddr;
  9. extern int handlerflag;
  10. extern int abortstart;
  11. extern struct breakelem brtable[];
  12. extern struct regelem mpu[];
  13. register int vector;
  14. register int stacktype;
  15. register int instaddr;
  16. register int i;
  17. register int ispdelta;
  18.  
  19.     regdata[SR] = get16(stackptr);
  20.     regdata[PC] = get32(stackptr + 0x2);
  21.     vector = get16(stackptr + 0x6);
  22.     stacktype = (vector >> 12) & MASK4;
  23.     vector = (vector & MASK12) / 4;
  24.     handlerflag = 0;
  25.     switch (stacktype)
  26.     {
  27.         case 0:
  28.         case 1:
  29.             instaddr = regdata[PC];
  30.             ispdelta = 0x8;
  31.             break;
  32.         case 2:
  33.             instaddr = get32(stackptr + 0x8);
  34.             ispdelta = 0xc;
  35.             break;
  36.         case 9:
  37.             instaddr = get32(stackptr + 0x8);
  38.             ispdelta = 0x14;
  39.             break;
  40.         case 10:
  41.         case 11:
  42.             instaddr = regdata[PC];
  43.             ispdelta = 0;
  44.             break;
  45.     }
  46.     storereg(mpu);
  47.     switch (vector)
  48.     {
  49.         case 2:
  50.         case 3:
  51.             if (vector == 3)
  52.                 print("Address Error\n");
  53.             else
  54.                 {
  55.                 print("Bus Error\n");
  56.                 print("SSW=$%x   ",get16(stackptr + 0xa));
  57.                 if(bitnum(8,8,get16(stackptr + 0xa))==1)
  58.                     print("Data Cycle Fault Address=$%x\n",get32(stackptr + 0x10));
  59.                 }
  60.             print("\n");
  61.             printreg(mpu);
  62.             /* PRINT DISASM68.C OF PC VALUE HERE */
  63.             disasm(instaddr);
  64.             print("\n");
  65.             handlerflag = -1;
  66.             break;
  67.         case 4:
  68.             for (i = 0; i < MAXBR; i++)
  69.             {
  70.                 if ((brtable[i].address == instaddr) && (brtable[i].count != -1))
  71.                 {
  72.                     if (brtable[i].tempcount == 0)
  73.                     {
  74.                         mpu[ISP].value = mpu[ISP].value + ispdelta;
  75.                         mpu[A7].value = mpu[A7].value + ispdelta;
  76.                         print("Breakpoint at %c%8x\n",HEXDEL,instaddr);
  77.                         print("\n");
  78.                         printreg(mpu);
  79.                     /* ********************************* */
  80.                     /* PRINT DISASM68.C OF PC VALUE HERE */
  81.                         put16(instaddr,brtable[i].inst1);
  82.                         disasm(instaddr);
  83.                         put16(instaddr, BRTRAP);
  84.                         print("\n");
  85.                     /* ********************************* */
  86.                         brtable[i].tempcount = -1;
  87.                         for (i = 0; i < MAXBR;i++)
  88.                             if (brtable[i].count >= 0)
  89.                                 put16(brtable[i].address,brtable[i].inst1);
  90.                         i = 0;
  91.                         handlerflag = -1;
  92.                         break;
  93.                     }
  94.                     else if (brtable[i].tempcount == -1)
  95.                     {
  96.                         oldbraddr = brtable[i].address;
  97.                         put16(oldbraddr,brtable[i].inst1);
  98.                         put16(stackptr,regdata[SR] | TRACEON);
  99.                         tracecount = -1;
  100.                         i = 0;
  101.                         handlerflag = 0;
  102.                         break;
  103.                     }
  104.                     else
  105.                     {
  106.                         brtable[i].tempcount--;
  107.                         i = 0;
  108.                         handlerflag = 0;
  109.                         break;
  110.                     }
  111.                     break;
  112.                 }
  113.             }
  114.             if (i > 0)
  115.             {
  116.                 mpu[ISP].value = mpu[ISP].value + ispdelta;
  117.                 mpu[A7].value = mpu[A7].value + ispdelta;
  118.                 print("Illegal instruction at %c%8x\n",HEXDEL,instaddr);
  119.                 print("\n");
  120.                 printreg(mpu);
  121.                 handlerflag = -1;
  122.             }
  123.             break;
  124.         case 5:
  125.         case 6:
  126.         case 7:
  127.         case 8:
  128.         case 10:
  129.         case 11:
  130.         case 12:
  131.         case 13:
  132.         case 14:
  133.         case 15:
  134.         case 16:
  135.         case 17:
  136.         case 18:
  137.         case 19:
  138.         case 20:
  139.         case 21:
  140.         case 22:
  141.         case 23:
  142.         case 55:
  143.         case 59:
  144.         case 60:
  145.         case 61:
  146.         case 62:
  147.         case 63:
  148.         case 64:
  149.             switch(vector)
  150.             {
  151.                 case 5:
  152.                     print("Zero Divide\n");
  153.                     break;
  154.                 case 6:
  155.                     print("CHK,CHK2 Instruction\n");
  156.                     break;
  157.                 case 7:
  158.                     print("cpTRAPcc,TRAPcc,TRAPV Instruction\n");
  159.                     break;
  160.                 case 8:
  161.                     print("Priivilege Violation\n");
  162.                     break;
  163.                 case 10:
  164.                     print("A-Line \n");
  165.                     break;
  166.                 case 11:
  167.                     print("F-Line \n");
  168.                     break;
  169.                 case 12:
  170.                 case 16:
  171.                 case 17:
  172.                 case 18:
  173.                 case 19:
  174.                 case 20:
  175.                 case 21:
  176.                 case 22:
  177.                 case 23:
  178.                 case 55:
  179.                 case 59:
  180.                 case 60:
  181.                 case 61:
  182.                 case 62:
  183.                 case 63:
  184.                     print("(Unassigned, Reserved\n");
  185.                     break;
  186.                 case 64:
  187.                     print("Abort \n");
  188.                     break;
  189.                 case 13:
  190.                     print("Coprocessor Protocol Violation\n");
  191.                     break;
  192.                 case 14:
  193.                     print("Format Error\n");
  194.                     break;
  195.                 case 15:
  196.                     print("Uninitialized Interrupt\n");
  197.                     break;
  198.             }
  199.             print("\n");
  200.             printreg(mpu);
  201.             /* PRINT DISASM68.C OF PC VALUE HERE */
  202.             disasm(instaddr);
  203.             print("\n");
  204.             handlerflag = -1;
  205.             break;
  206.         case 9:
  207.             if (tracecount == -1)
  208.             {
  209.                 for (i = 0; i < MAXBR; i++)
  210.                 {
  211.                     if (brtable[i].address == oldbraddr)
  212.                     {
  213.                         put16(oldbraddr,BRTRAP);
  214.                         put16(stackptr,regdata[SR] & ~TRACEON);
  215.                         brtable[i].tempcount == brtable[i].count;
  216.                         break;
  217.                     }
  218.                 }
  219.             }
  220.             else if (tracecount > 0)
  221.                 tracecount--;
  222.             else
  223.             {
  224.                 mpu[ISP].value = mpu[ISP].value + ispdelta;
  225.                 mpu[SR].value = mpu[SR].value & ~TRACEON;
  226.                 mpu[A7].value = mpu[A7].value + ispdelta;
  227.                 print("\n");
  228.                 for (i = 0; i < MAXBR; i++)
  229.                 {
  230.                 if ((brtable[i].address == regdata[PC]) && (brtable[i].count != -1))
  231.                     {
  232.                     print("Trace at Breakpoint (%x)\n",brtable[i].address);
  233.                     break;
  234.                     }
  235.                 }
  236.                 if(i == MAXBR)
  237.                     print("Trace at %c%8x\n",HEXDEL,regdata[PC]);
  238.                 printreg(mpu);
  239.                 /* PRINT DISASM68.C OF PC VALUE HERE */
  240.                 disasm(regdata[PC]);
  241.                 print("\n");
  242.                 handlerflag = -1;
  243.             }
  244.             break;
  245.         case 24:
  246.             print("Spurious Interrupt\n");
  247.             print("\n");
  248.             printreg(mpu);
  249.             /* PRINT DISASM68.C OF PC VALUE HERE */
  250.             disasm(instaddr);
  251.             print("\n");
  252.             handlerflag = -1;
  253.             break;
  254.         case 25:
  255.         case 26:
  256.         case 27:
  257.         case 28:
  258.         case 29:
  259.         case 30:
  260.         case 31:
  261.             print("Autovector interrupt level %d\n",vector - 24);
  262.             print("\n");
  263.             printreg(mpu);
  264.             /* PRINT DISASM68.C OF PC VALUE HERE */
  265.             disasm(instaddr);
  266.             print("\n");
  267.             handlerflag = -1;
  268.             break;
  269.         case 32:
  270.         case 33:
  271.         case 34:
  272.         case 35:
  273.         case 36:
  274.         case 37:
  275.         case 38:
  276.         case 39:
  277.         case 40:
  278.         case 41:
  279.         case 42:
  280.         case 43:
  281.         case 44:
  282.         case 45:
  283.         case 46:
  284.         case 47:
  285.             print("TRAP #%d\n",vector - 32);
  286.             print("\n");
  287.             printreg(mpu);
  288.             /* PRINT DISASM68.C OF PC VALUE HERE */
  289.             disasm(instaddr);
  290.             print("\n");
  291.             handlerflag = -1;
  292.             break;
  293.         case 48:
  294.         case 49:
  295.         case 50:
  296.         case 51:
  297.         case 52:
  298.         case 53:
  299.         case 54:
  300.             print("FPCP Exception vector #%d\n",vector);
  301.             print("\n");
  302.             printreg(mpu);
  303.             /* PRINT DISASM68.C OF PC VALUE HERE */
  304.             disasm(instaddr);
  305.             print("\n");
  306.             handlerflag = -1;
  307.             break;
  308.         case 56:
  309.         case 57:
  310.         case 58:
  311.             print("PMMU Exception vector #%d\n",vector);
  312.             print("\n");
  313.             printreg(mpu);
  314.             /* PRINT DISASM68.C OF PC VALUE HERE */
  315.             disasm(instaddr);
  316.             print("\n");
  317.             handlerflag = -1;
  318.             break;
  319.         default:
  320.             print("User Defined Vector #%d\n",vector);
  321.             print("\n");
  322.             printreg(mpu);
  323.             /* PRINT DISASM68.C OF PC VALUE HERE */
  324.             disasm(instaddr);
  325.             print("\n");
  326.             handlerflag = -1;
  327.             break;
  328.     }
  329. }
  330.